﻿@model IEnumerable<Role>
@{
    var modelName = EntityNames.Role;
    ViewBag.PageTitle = modelName;
    ViewBag.Title = ViewBag.PageTitle + "_安全";
}
<div class="panel panel-default">
    <div class="panel-heading text-right">           
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ModalRoleForm"><i class="fa fa-pencil fa-fw"></i>新建角色</button>
    </div>
    <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>操作</th>
                    <th>
                        角色名称
                    </th>
                    <th>
                        描述
                    </th>
                </tr>
            </thead>
            <tbody id="RoleList">
               @Html.Partial("_List",Model)
            </tbody>
        </table>   
</div>

<div id="edit-container">
    @Html.Action("EditRole")
</div>

<div id="menus-container">    
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@section Footer{
@Scripts.Render("~/bundles/jqueryvalWithBootstrap")
    <script>
        function onAjaxComplete() {
            $('#ModalRoleForm').modal();
        }
        
        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin")
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save")
        }
        function updateSuccess(data) {
            var title = '@ViewBag.PageTitle';
            Common.ShowBoxWithFuncBack(data, title, submitSuccess);          

        }
        function submitSuccess(id, htmlData) {
            $('#ModalRoleForm').modal('hide');
            $("#RoleList").html(htmlData);
        }



        function onAjaxCompleteRoleMenus() {
            $('#modalRoleMenuForm').modal();

            $('input[name=menuId]').change(function () {
                if ($(this).is(":checked")) {
                    var checkboxs = $(this).closest("li").find("input[name=menuId]").prop("checked", "checked");
                } else {
                    $(this).closest("li").find("input[name=menuId]").removeAttr("checked");
                }

            });
        }

        function updateSuccessRoleMenus(data) {
            Common.ShowBox(data.Status, data.Message, "@modelName")
            $('#modalRoleMenuForm').modal('hide');           

        }



        $(function () {


            var modelName = "@modelName";

            //确认框默认语言
            bootbox.setDefaults({
                locale: "zh_CN"
            });


            //delete
            $(document).on("click", '.delete-item', function (e) {
                e.preventDefault();

                var url = $(this).attr('href');
                var that = $(this);
                bootbox.setLocale("zh_CN");
                bootbox.confirm("你确定要删除此项吗？", function (result) {
                    if (result) {
                        /*DELETE*/
                        var title = "@ViewBag.Title";
                        Common.DeleteItem(url, title, that);
                    }
                });

            });


          

        });
    </script>

}